﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BKH.BLL
{
    class GiuongBUO:IBUO<tbl_Giuong>
    {
        HospitalDBDataContext context = new HospitalDBDataContext();
        public bool Insert(tbl_Giuong obj)
        {
            try
            {
                context.tbl_Giuongs.InsertOnSubmit(obj);
                context.SubmitChanges();
                return true;

            }
            catch (Exception)
            {

                return false;
            }
        }

        public bool Delete(int id)
        {
            tbl_Giuong item = context.tbl_Giuongs.Where(n => n.BedID == id).FirstOrDefault<tbl_Giuong>();
            try
            {
                context.tbl_Giuongs.DeleteOnSubmit(item);
                context.SubmitChanges();
                return true;
            }
            catch (Exception)
            {

                return false;
            }

        }

        public bool Delete(tbl_Giuong obj)
        {
            throw new NotImplementedException();
        }

        public List<tbl_Giuong> GetAll()
        {
            return context.tbl_Giuongs.ToList<tbl_Giuong>();
        }

        public tbl_Giuong GetSingle(int id)
        {
            return context.tbl_Giuongs.Where(n => n.BedID == id).ToList<tbl_Giuong>().FirstOrDefault();
        }

        public bool Update(int id, tbl_Giuong obj)
        {
            try
            {
                tbl_Giuong bed = context.tbl_Giuongs.Where(n => n.BedID == id).ToList<tbl_Giuong>().FirstOrDefault();
                bed.TenGiuong = obj.TenGiuong;
                bed.IsEmpty = obj.IsEmpty;
                context.SubmitChanges();
                return true;

            }
            catch (Exception)
            {

                return false;
            }
        }

        //public List<tbl_Giuong> GetEmptyBed()
        //{
        //    return context.tbl_Giuongs.Where(empty => empty.IsEmpty == (int)GiuongTrong.Empty).ToList<tbl_Giuong>();
        //}
    }
}
